package com.mediacloud.app.newsmodule.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.mediacloud.app.newsmodule.R;


/**
 * Created by Yoake on 2018/9/10.
 */

public class ConfirmPop extends PopupWindow {
    private Context context;
    private TextView tx_make_sure;
    private TextView tx_content;
    private TextView tx_title;

    public ConfirmPop(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public ConfirmPop(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    private void init() {

        View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_layout_, null);
        this.setContentView(contentView);
        //自定义基础，设置我们显示控件的宽，高，焦点，点击外部关闭PopupWindow操作
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        //更新试图
        this.update();
        this.setBackgroundDrawable(new ColorDrawable(0000000000));
        tx_make_sure = contentView.findViewById(R.id.tx_make_sure);
        tx_content = contentView.findViewById(R.id.tx_content);
        tx_title = contentView.findViewById(R.id.tx_title);

    }

    public void show(View view, String title, String msg, View.OnClickListener listener) {
        tx_title.setText(title);
        tx_content.setText(msg);
        tx_make_sure.setOnClickListener(listener);
        showAtLocation(view, Gravity.CENTER, 0, 0);
    }
}